#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<string>
#include<stack>

using namespace std;

bool checkAlmostEquivalent(string word1, string word2) {
    int arr1[28] = { 0 }, arr2[28] = { 0 };
    int n = word1.size();
    for (int i = 0; i < n; i++)
    {
        arr1[word1[i] - 'a']++;
        arr2[word2[i] - 'a']++;
    }
    for (int i = 0; i < 26; i++)
    {
        if (abs(arr1[i] - arr2[i]) > 3) return false;
    }
    return true;
}

string decodeString(string s) {
    string ans;
    stack<pair<int, int>> stk;
    int count = 0;
    for (auto x : s) {
        if (isdigit(x))
            count = 10 * count + (x - '0');
        else if (x == '[') {
            stk.push({ count, ans.size() });
            count = 0;
        }
        else if (isalpha(x))
            ans += x;
        else if (x == ']') {
            int n = stk.top().first;
            string str = ans.substr(stk.top().second, ans.size() - stk.top().second);
            for (int i = 0; i < n - 1; i++) {
                ans += str;
            }
            stk.pop();
        }
    }
    return ans;
}

int main()
{
    string s = { "3[a2[c]]" };
    cout << decodeString(s) << endl;
    return 0;
}
